package com.springboot.blog.dto;

import java.io.Serializable;

public class LayResponse implements Serializable {
    private static final long serialVersionUID = 1L;
    private int code;
    private String msg;
    private Object data;
    private Long count;

    public LayResponse() {
    }

    public LayResponse(Long count,Object data) {
        setCount(count);
        setData(data);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public LayResponse success(String msg){
        setMsg(msg);
        setCode(0);
        return this;
    }
    public LayResponse success(){
        setCode(0);
        if(this.msg==null){
            setMsg("成功!");
        }
        return this;
    }
    public LayResponse error(String msg){
        setMsg(msg);
        setCode(500);
        return this;
    }
    public LayResponse error(){
        setCode(500);
        if(this.msg==null){
            setMsg("失败!");
        }
        return this;
    }
    public boolean hasError(){
        return 200!=this.code;
    }
    public boolean succeed(){
        return 0==this.code;
    }
    public Object data(){
        return this.data;
    }
    public LayResponse data(Object data){
        setData(data);
        return this;
    }

    public Long getCount() {
        return count;
    }

    public LayResponse setCount(Long count) {
        this.count = count;
        return this;
    }
}
